package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class HJ35_预定酒店 {
  public static void main(String[] args) throws FileNotFoundException {
    Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/35.txt"));
    int N = in.nextInt();
    int k = in.nextInt();
    int x = in.nextInt();
    List<hotel> list = new ArrayList<>();
    while (N-- > 0) {
      int price = in.nextInt();
      int jiagecha = Math.abs(price - x);
      list.add(new hotel(price, jiagecha));
    }
    list.sort(
        (a, b) -> {
          if (a.jiagecha == b.jiagecha) {
            return a.price - b.price;
          } else {
            return a.jiagecha - b.jiagecha;
          }
        });
    int[] res = new int[k];
    for (int i = 0; i < k; i++) {
      res[i] = list.get(i).price;
    }
    Arrays.sort(res);
    for (int i = 0; i < k; i++) {
      System.out.print(res[i] + " ");
    }
  }

  static class hotel {
    int price;
    int jiagecha;

    public hotel(int price, int jiagecha) {
      this.price = price;
      this.jiagecha = jiagecha;
    }
  }
}
